package cn.pilipa.common.json;

import static org.assertj.core.api.Assertions.assertThat;

import cn.pilipa.common.config.MongoConfigTest;
import cn.pilipa.common.config.data.ObjHolder;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
@ActiveProfiles("integTest")
public class SpecialObjectJsonTests {


  ObjHolder objHolder = MongoConfigTest.objHolder;


  @Autowired
  private ObjectMapper objectMapper;

  static final String content = "{\"name\":\"n\",\"money\":\"CNY99.00\","
                        + "\"localDate\":\"2018-04-16\",\"yearMonth\":\"2018-04\"}";

  @Test
  public void serialize() throws Exception {
    final String json = objectMapper.writeValueAsString(objHolder);
    assertThat(json).isEqualTo(content);
  }

  @Test
  public void deserialize() throws Exception {
    assertThat(
      objectMapper.readValue(content, ObjHolder.class)
    ).isEqualToComparingFieldByField(objHolder);
  }

}
